;
(function() {
  var chart = null;
  var ytParkingNum = 0;

  var industry = {
    init: function() {
      this.data()
    },
    //统计行业出租面积分布
    data: function() {

      function GetDateStr(AddDayCount) {
        var dd = new Date();
        dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1; //获取当前月份的日期
        var d = dd.getDate();
        return y + "-" + tzero(m) + "-" + tzero(d);
      }

      var data = {
        date: GetDateStr(-1)
      }

      var self = this;
      hlhttp.get({
        url: 'report/acreage_by_unit_type',
        data: data,
        success: function (data) {
          if (data.length === 0) {
            $('#yt-chart-container').html('暂无数据').css('line-height', '250px').addClass('text-center');
            return
          }

          var dealData = [],colorArr = [],totalArea = 0;

          $('.js-yt-no-data').hide()
          data.map(function (item) {
            if (item.businessType === 'BG') {
              dealData.push([hlCodeConvert.businessType(item.businessType), Number(item.acreage)])
              colorArr.push('#A88EDA')
            }
            if (item.businessType === 'SP') {
              dealData.push([hlCodeConvert.businessType(item.businessType), Number(item.acreage)])
              colorArr.push('#7FC684')
            }
            if (item.businessType === 'ST') {
              ytParkingNum = item.count
              dealData.push([hlCodeConvert.businessType(item.businessType), Number(item.acreage)])
              colorArr.push('#69C8FF')
            }
            if (item.businessType === 'ETC') {
              dealData.push([hlCodeConvert.businessType(item.businessType), Number(item.acreage)])
              colorArr.push('#F8D86A')
            }

            totalArea += Number(item.acreage)
          })

          setTimeout(function() {
            self.charts(dealData,colorArr,totalArea)
          }, 500);
        }
      })
    },
    //charts
    charts: function(data,colorArr,totalArea) {
      $(function() {
        Highcharts.chart('yt-chart-container',
          {
            chart: {
              plotBackgroundColor: null,
              plotBorderWidth: null,
              plotShadow: false
            },
            colors:colorArr,
            title: {
                floating: true,
                text: '<div style="padding:20px 0;"><p style="color:#666;font-size:12px;">总面积(㎡)</p><div style="color:#F0A158;font-size:16px;">' + totalArea.toFixed(2) + '</div></div>',
                style: {
                    textAlign: 'center',
                    top: '50%',
                    left: '50%',
                    transform: 'translate(0,-40%)',
                },
                useHTML:true,
            },
            tooltip: {
              headerFormat: '{series.name}<br>',
              pointFormat: '{point.name}: <b>{point.percentage:.2f}%</b>'
            },
            plotOptions: {
              pie: {
                size: '100%',
                showInLegend: true,
                dataLabels: { connectorWidth: 0 , enabled: false}
              }
            },
            series: [{
              type: 'pie',
              innerSize: '60%',
              name: '业态类型占比',
              data: data
            }],
            legend: {
              enabled: true,
              itemDistance:20
            }
          },
          function(c) {
            // 环形图圆心
            var centerY = c.series[0].center[1];
            var titleHeight = parseInt(c.title.styles.fontSize);
            c.setTitle({
              y: centerY + titleHeight / 2
            });
            chart = c;
          }
        )
      });

    }
  }

$(function () {
    industry.init()
})

  function tzero(n) {
    return n < 10
      ? '0' + n
      : '' + n
  }

}())
